unit FornecedorSearchFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, Buttons, StdCtrls, DBCtrls, MainSearchFr;

type

  { TFornecedorSearchFrame }

  TFornecedorSearchFrame = class(TMainSearchFrame)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    id_fornecedor: TEdit;
    id_pessoa: TEdit;
    nome_pessoa: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    ativo: TRadioGroup;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure LocalizarButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

implementation

uses Initializator, FornecedorDM, QueryConditions, PessoaSearchFr, RamoSearchFr, MainFr;

{ TFornecedorSearchFrame }

procedure TFornecedorSearchFrame.BitBtn1Click(Sender: TObject);
begin
  TheControl.ShowForeignFrame(TMainFrame(PessoaSearchFrame));
end;

procedure TFornecedorSearchFrame.BitBtn2Click(Sender: TObject);
begin
  TheControl.ShowFrame(TMainFrame(FornecedorRecordFrame));
end;

procedure TFornecedorSearchFrame.LocalizarButtonClick(Sender: TObject);
var
  condicoes: TQueryConditions;
  m: string;
begin
  if ativo.ItemIndex = 0 then begin
    m := 'S';
  end else begin
    m := 'N';
  end;
  condicoes := TQueryConditions.Create(CON_AND);
  Condicoes.AddJoinField('f.id_fornecedor', 'p.id_pessoa');
  Condicoes.AddJoinField('c.id_cidade', 'p.id_cidade');
  condicoes.Add('f.id_fornecedor', id_fornecedor.Text);
  condicoes.AddText('p.nome_pessoa', nome_pessoa.Text);
  condicoes.Add('ativo', m);
  FornecedorData.Search(condicoes, 'fornecedor as f, pessoa as p, cidade as c');
end;

initialization
  {$I fornecedorsearchfr.lrs}

end.

